<template>
  <div>
    <el-dialog
      title="医生履约"
      :visible.sync="addDiavisible"
      width="50%"
      @close="cancel"
      @opened="beforeopen"
    >
      <!-- 表格 -->
      <el-table
        class="mt-20"
        ref="tableRef"
        :data="tableData"
        border
        stripe
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="index" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="content" label="服务内容" align="center">
        </el-table-column>
        <el-table-column type="selection" width="55" :selectable='selectEnable'> </el-table-column>
      </el-table>
      <span slot="footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { addPerformance } from "@/api/family_doctor/family_doctor";
import { selectPackageDetailById } from "@/api/family_doctor/servicePackageDetail";
export default {
  data() {
    return {
      addDiavisible: false,
      tableData: [],
      param: {
        packageDetailIds: [],
        signPhoto: "",
        performanceTime: "",
        contractId: "",
        packageServiceId: "",
        idCard: "",
      },
    };
  },
  created() {},
  methods: {
    //关闭
    cancel() {
      this.$refs.tableRef.clearSelection();
      this.addDiavisible = false;
    },
    //弹窗渲染之前
    beforeopen() {},
    //供父组件调用函数
    openDialog(row, idCard, id) {
		this.tableData = [];
      this.pushTable(row.servicePackageId);
	  console.log(this.tableData);
      this.param.packageServiceId = row.servicePackageId;
      this.param.idCard = idCard;
      this.param.contractId = id;
      this.addDiavisible = true;
    },
    handleSelectionChange(selection) {
      this.param.packageDetailIds = [];
      selection.forEach((e) => {
        this.param.packageDetailIds.push(e.id);
      });
    },
    submit() {
      addPerformance(this.param).then((res) => {
        if (res.code == "AA000000") {
          this.$message.success(res.msg);
					// window.location.reload()
          this.cancel();
        }
      });
    },
    //表格拼接
    pushTable(id) {
     selectPackageDetailById(id).then(res=>{
		 
		var list =  res.data
		console.log(list)
		list.forEach(e=>{
			this.tableData.push({
						 content:e.content,
						 state:e.state,
						 id:e.id,
			})
		})
		
	 });
    },
    selectEnable(row){
      if(row.state==0){
        return true;
      }
    }
  },
};
</script>
<style lang="less" scoped>
</style>